__all__ = ['Tower', 'ArrowTower', 'IceTower', 'StoneTower', 'FireTower']

class Tower(object):
    def __init__(self, gunshot, firepower, cd, level, pos):
        self.gunshot = gunshot
        self.firepower = firepower
        self.cd = cd
        self.level = level
        self._cd_time = 0
        self.position = pos


    def attack(self, monster):
        monster.attacked_by(self.firepower)
        self._cd_time = self.cd

    def reflesh(self):
        if self._cd_time > 0 : self._cd_time -= 1

    def active(self):
        return self._cd_time == 0

class ArrowTower(Tower):
    def __init__(self, gunshot, firepower, cd, level, pos):
        super(ArrowTower, self).__init__(gunshot, firepower, cd, level, pos)
        
    def update_cost(self):
        pass

class IceTower(Tower):
    def __init__(self, gunshot, firepower, cd, level, pos, freeze):
        super(IceTower, self).__init__(gunshot, firepower, cd, level, pos)
        self._freeze_rate = freeze['rate']
        self._freeze_time = freeze['time']

    def attack(self, monster):
        super(IceTower, self).attack(monster)
        monster.freeze(time = self._freeze_time, rate = self._freeze_rate)

    def update_cost(self):
        pass

class StoneTower(Tower):

    # s_rate, s_range = sputter-rate and sputter-range
    def __init__(self, gunshot, firepower, cd, level, pos, s_rate, s_range, the_map):
        super(StoneTower, self).__init__(gunshot, firepower, cd, level, pos)
        self._s_rate, self._s_range = s_rate, s_range
        self._map = the_map

    def attack(self, monster):
        super(StoneTower, self).attack(monster)

        sputter_attack = self.firepower * self._s_rate
        sputter_targets = self._map.targets(monster.position, self._s_range)
        for m in sputter_targets :
            m.attacked_by(sputter_attack)

    def update_cost(self):
        pass

class FireTower(StoneTower):
    def attack(self, monster):
        super(StoneTower, self).attack(monster)

        fire_attack = self.firepower * self._s_rate
        fire_targets = self._map.targets(monster.position, self._s_range)
        for m in fire_targets :
            m.fire_attacked_by(fire_attack)
